package com.sgcc.pda.hzaidl.impl;


import android.os.RemoteException;
import android.text.TextUtils;

import com.sgcc.pda.cepriaidl.AIDLUtils;

import com.sgcc.platforminterface.PlatfInterfManager;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @创建者：suven on 2019/12/17 12:28
 * @描述：
 * @版本：1.0
 * @修改人：
 * @修改时间：
 * @修改说明：
 * @修改版本：
 */
public class HardwareManager {
    private static HardwareManager mInstance;

    /**
     * 单例
     *
     * @return
     */
    public static synchronized HardwareManager getInstance() {
        if (mInstance == null) {
            mInstance = new HardwareManager();
        }
        return mInstance;
    }


    /**
     * 设置系统时钟
     *
     * @param dateTime 设置日期时间值的字符串yyyy-MM-dd HH:mm:ss，如2016-10-28 16:34:45
     * @return 成功返回 true，失败返回 false
     */
    public boolean setDateTime(String dateTime) {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            JSONObject jb = new JSONObject();
            try {
                jb.put("dateTime", dateTime);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            String resutl = HardWareUtil.requestBasicData("setDateTime", jb.toString());
            return TextUtils.isEmpty(resutl) ? false : Boolean.parseBoolean(resutl);
        } else {
            return AIDLUtils.setDateTime(dateTime);
        }

    }

    /**
     * 添加 APN 设置，同时设置为默认 APN
     *
     * @param apnName  APN 设置的名称标识
     * @param apn      APN 内容
     * @param userName 用户名，可为空或 null
     * @param password 密码，可为空或 null
     * @return 成功返回 true，失败返回 false
     */
    public boolean addApn(String apnName, String apn, String userName, String password) {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            JSONObject jb = new JSONObject();
            try {
                jb.put("apnName", apnName);
                jb.put("apn", apn);
                jb.put("userName", userName);
                jb.put("password", password);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            String resutl = HardWareUtil.requestBasicData("addApn", jb.toString());
            return TextUtils.isEmpty(resutl) ? false : Boolean.parseBoolean(resutl);
        } else {
            return AIDLUtils.addApn(apnName, apn, userName, password);
        }

    }


    /**
     * 获取so库的厂家编码
     *
     * @return So库的厂家编码
     */

    public int getCompany() {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            try {
                String company = HardWareUtil.requestHardwareDataString("so_getCompany");
                return TextUtils.isEmpty(company) ? 0 : Integer.parseInt(company);
            } catch (Exception e) {
                e.printStackTrace();
                return 0;
            }
        } else {
            try {
                return com.sgcc.pda.hw.impl.HardwareManager.getInstance().getHardwareManager().getCompany();
            } catch (RemoteException e) {
                e.printStackTrace();
                return 0;
            }
        }
    }


    /**
     * 获取设备型号
     *
     * @return 成功返回设备型号，失败返回空字符串
     */
    public String getDeviceModel() {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            try {
                return HardWareUtil.requestBasicData("getDeviceModel");
            } catch (Exception e) {
                e.printStackTrace();
                return "";
            }
        } else {
            return AIDLUtils.getDeviceModel();
        }
    }

    /**
     * 获取设备序列号
     *
     * @return 成功返回设备序列号，失败返回空字符串
     */
    public String getDeviceSn() {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            try {
                return HardWareUtil.requestBasicData("getDeviceSn");
            } catch (Exception e) {
                e.printStackTrace();
                return "";
            }
        } else {
            return AIDLUtils.getDeviceSn();
        }
    }

    /**
     * 获取设备系统版本号
     *
     * @return 成功返回设备系统版本号，失败返回空字符串
     */
    public String getOSVersion() {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            try {
                return HardWareUtil.requestBasicData("getOSVersion");
            } catch (Exception e) {
                e.printStackTrace();
                return "";
            }
        } else {
            return AIDLUtils.getOSVersion();
        }
    }

    /**
     * 获取设备硬件版本号
     *
     * @return 成功返回设备硬件版本号，失败返回空字符串
     */
    public String getDeviceHardVersion() {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            try {
                return HardWareUtil.requestBasicData("getDeviceHardVersion");
            } catch (Exception e) {
                e.printStackTrace();
                return "";
            }
        } else {
            return AIDLUtils.getDeviceHardVersion();
        }
    }

    /**
     * 获取设备生产日期
     *
     * @return 成功返回设备生产日期，失败返回空字符串
     */
    public String getProductionDate() {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            try {
                return HardWareUtil.requestBasicData("getProductionDate");
            } catch (Exception e) {
                e.printStackTrace();
                return "";
            }
        } else {
            return AIDLUtils.getProductionDate();
        }
    }


}
